﻿using Common.DataAnnotations;
using Newtonsoft.Json;
using Newtonsoft.Json.Serialization;
using System;
using System.Collections.Generic;
using System.Reflection;
using System.Text;

namespace Common.Web
{
    /// <summary>
    /// 敏感数据Json契约
    /// </summary>
    public class SensitiveDataContract : Newtonsoft.Json.Serialization.CamelCasePropertyNamesContractResolver
    {
        /// <summary>
        /// 创建属性
        /// </summary>
        /// <param name="member"></param>
        /// <param name="memberSerialization"></param>
        /// <returns></returns>
        protected override JsonProperty CreateProperty(MemberInfo member, MemberSerialization memberSerialization)
        {
            var property = base.CreateProperty(member, memberSerialization);
            if (member.GetCustomAttribute<SensitiveDataAttribute>(true) != null)
            {
                property.Converter = new SensitiveDataConverter();
            }

            return property;
        }
    }
}
